<template>
	<view>
		<uni-popup ref="commendAddRef" type="bottom" :maskClick="false">
			<view class="">
				<view class="body">
					<view class="tray_data">
						<uni-forms :modelValue="trayData" >
							<uni-forms-item label="件号:" name="itemnumber" style="width: 200px;">
								<uni-easyinput  type="text" v-model="trayData.itemnumber"  />
							</uni-forms-item>
						
							<uni-forms-item label="仓库:" name="flot" style="width: 200px;">
								<uni-data-select v-model="trayData.stockNo" :localdata="stockList"
								 
								placeholder="请选择仓库"></uni-data-select>

							</uni-forms-item>
							<uni-forms-item label="物料编码" name="foperpno" style="width: 200px;">
								<uni-easyinput  type="text" v-model="trayData.mateiralNo"  />
							</uni-forms-item>
							<uni-forms-item label="批号" name="foperpno" style="width: 200px;">
								<uni-easyinput  type="text" v-model="trayData.flot"  />
							</uni-forms-item>
							<uni-forms-item label="数量:" name="fqty" style="width: 200px;">
								<uni-easyinput  type="number" v-model="trayData.fqty"  />
							</uni-forms-item>
							<button @click="selectInventory" class="footerBtn concle" ><i
									></i>查询
							</button>
						</uni-forms>
					</view>
					<view class="footerPanel">
						<view class="footerPanel_body">
							<button @click="closeInfoPop" class="footerBtn concle" ><i
									></i>取消
							</button>
	
							<button @click="addTrayFeed" class="footerBtn save" ><i
									class="iconfont icon-duihao btn_icon" ></i>新增
							</button>
							
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
		<!-- 扫描仓位码后弹出领料界面，可以修改领料信息 -->
		<add-pick ref="pickRef"></add-pick>
	<!-- 推荐仓位-->
	<Commend ref="commendRef" @back="back"></Commend>
	</view>
</template>

<script>
	import Commend from "@/pages/pop/commend-scanFeed.vue"
	import {
	createFeedTemp,
	commendLocationByItem,
	selectstock}  from '@/utils/api.js'
	import AddPick from "@/pages/pop/add-pick-commend.vue"
	
	export default {
		components: {
			AddPick,
			Commend
			
		},
		data() {
			return {
				trayData:{},//托盘信息
				trayCount : 0, //托盘数量
				planData : {}, //工序计划数据
				type : '',
				stockList:[],
				operNo : ''
			};
		},
		mounted() {
			this.getStockList()
			// this.initData()
		},
		methods: {
			
			/**
			 * @param {Object} e库存查询返回物料编码
			 */
			back(e){
				this.$set(this.trayData,'mateiralNo',e.fmaterialNo)
				this.$set(this.trayData,'flot',e.batchNo)
				this.$set(this.trayData,'stockNo',e.stockNo)
				// this.trayData.mateiralNo = e
			},
			/**
			 * 查询库存
			 */
			selectInventory(){
				let self = this;
				commendLocationByItem({
					itemnumber : this.trayData.itemnumber,
					stockNo : this.trayData.stockNo,
				}).then(res =>{
					if (res.data.status == 200){
						self.commedList = res.data.data.dataList ?? []
						
					} 
					let param = {
						dataList : self.commedList
					}
		
					this.$refs.commendRef.open(param)
				})
				
			},
			/** 查询仓库*/
			getStockList() {
				selectstock({}).then(res =>{
					this.stockList = res.data.data.dataList
				})
			},
			//添加到补料临时数据
			addTrayFeed(){
				let _this = this;
				if (!this.trayData.fqty){
					uni.showToast({
						icon:"error",
						title:'数量必填'
					})
					return;
				}
				uni.showModal({
					title:'提示',
					content:'确认新增',
					success(res) {
						if (res.confirm){
							createFeedTemp( {
								operNo : _this.operNo,
								trayData : _this.trayData
							}).then(result => {
						
							if (result.data){
								uni.showToast({
									title:'新增成功',
									icon:'none'
								})
								_this.$emit('success','')
								_this.close()
							}
							
							
							})
						
						}
					}
				})
			},
			
			
			updateFqty(e){
				if (e.pickCount > e.FBASEQTY){
					e.pickCount = e.FBASEQTY
				}
			},
		
		
			closeInfoPop() {
				this.$refs.commendAddRef.close()
			},
			
			open(data) {
				this.operNo = data.operNo
				this.$refs.commendAddRef.open('center')
	
			},
			close() {
				this.$refs.commendAddRef.close()
			}
		},
		onLoad() {
		
		}
	}
</script>

<style lang="scss">

	.body{
	  background-color: aliceblue;
	  width: 85vw;
	  min-height: 50vh;
	  padding-bottom: 70px; /* 增加底部内边距为按钮留出空间 */
	  position: relative; /* 为按钮区域定位做准备 */
	}
	 
	.tray_data{
	  margin-top: 8px; /* 减小上边距 */
	  width: 100%;
	  
	  /* 调整表单项间距 */
	  ::v-deep .uni-forms-item {
	    margin-bottom: 8px !important; /* 减小行间距 */
	    min-height: 36px !important; /* 减小最小高度 */
	    
	    &__label {
	      font-size: 18px !important;
	      margin-bottom: 2px !important; /* 标签与输入框间距 */
	    }
	  }
	}
	
	.uni-forms-item {
	  align-items: flex-start !important; /* 顶部对齐 */
	  min-height: 36px; /* 设置统一高度 */
	}
	 
	/* 调整标签字体大小 */
	.tray_data ::v-deep .uni-forms-item__label {
		padding-left: 10px;
	  font-size: 20px !important;
	  color: #000000 !important;   /* 纯黑字体 */
	}
	 
	
	.tray_data ::v-deep .uni-forms-item input {
	  font-size: 20px !important;
	}
	 /* 特殊处理数量输入框 */
	 .tray_data ::v-deep .uni-easyinput {
		height: 50px;
	   font-size: 30px !important;
	   width: 120% !important; /* 保持原有输入框宽度 */
	 }
	 /* 调整标签组件样式 */
	 .tray_data ::v-deep .uni-tag {
	   font-size: 18px !important;
	   margin-left: 8px; /* 调整标签与文字间距 */
	 }
	 .uni-forms-item ::v-deep .uni-forms-item__label {
	   white-space: nowrap;  /* 禁止换行 */
	   min-width: 100px !important;  /* 设置最小宽度 */
	 }
	
	/* 底部按钮 - 修改布局 */
	.footerPanel {
	  position: absolute; /* 绝对定位 */
	  bottom: 30px;       /* 距离底部10px */
	  left: 0;
	  right: 0;
	  height: 60px;
	
	  .footerPanel_body {
	    display: flex;
	    justify-content: space-between; /* 左右分布按钮 */
	    width: 100%;
	    padding: 0 10px;
	    box-sizing: border-box;
	    
	    .footerBtn {
	      height: 50px;
	      min-width: 115px;
	      display: flex;
	      line-height: 1;
	      font-size: 18px; /* 适当增大字体 */
	      border-radius: 8px;
	      align-items: center;
	      justify-content: center;
	      box-shadow: 0 2px 5px rgba(0,0,0,0.2);
	      color: #fff;
	      border: none;
	      // margin: 0 10px;
	      
	      /* 取消按钮 - 左下角 */
	      &.concle {
	        background-color: #a0a0a0;
	        align-self: flex-start; /* 左对齐 */
			margin-left: 10px;
	      }
	      
	      /* 提交按钮 - 右下角 */
	      &.save {
	        background-color: $uni-color-success;
	        align-self: flex-end; /* 右对齐 */
				margin-left: 30px;
	      }
	    }
	  }
	}
</style>
